﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PosTranferUtils
{

    /// <summary>
    /// 屏幕坐标和UI本地坐标之间的相互转换
    /// </summary>
    /// <param name="uiTransform"></param>
    /// <param name="srcPos"></param>
    /// <param name="isToScreen">true表示把传入的srcPos转换到屏幕坐标</param>
    /// <param name="uiCam"></param>
    /// <returns></returns>
    public static Vector3 ScreenLocalPosTrans(Transform uiTransform,Vector3 srcPos,bool isToScreen,Camera uiCam)
    {
        if (isToScreen)
        {
            //uiTransform.TransformPoint 把屏幕坐标转换成世界坐标
            return uiCam.WorldToScreenPoint(uiTransform.TransformPoint(srcPos)); 
        }
        Vector3 worldPos = uiCam.ScreenToWorldPoint(srcPos);
        return uiTransform.InverseTransformPoint(worldPos);    
    }
    
    
    

}
